﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RouterControl.Whs.Wizards;

namespace RouterControl.WhsAddIn.Wizards
{
    public partial class EditPortForwardingPortAndProtocol : WizardPageClientBannerTop
    {
        private EditPortForwarding ParentWizard2
        {
            get { return (EditPortForwarding)this.ParentWizard; }
        }

        public EditPortForwardingPortAndProtocol()
        {
            InitializeComponent();
        }

        public override void StartRealWork()
        {
            base.StartRealWork();

            // load values
            var fw = this.ParentWizard2.Forwarding.Value;

            this.protocolUdpRB.Checked = fw.IsUDP;

            if (fw.ExternalPort >= 1 && fw.ExternalPort <= 65535)
                this.externalPort.Value = fw.ExternalPort;

            if (fw.InternalPort >= 1 && fw.InternalPort <= 65535)
                this.internalPort.Value = fw.InternalPort;
        }

        private void EditPortForwardingPortAndProtocol_BackButtonClick(object sender, EventArgs e)
        {
            SetCurrentPage<EditPortForwardingWelcome>();
        }

        private void EditPortForwardingPortAndProtocol_OkButtonClick(object sender, EventArgs e)
        {
            // save values
            var fw = this.ParentWizard2.Forwarding.Value;

            fw.IsUDP = this.protocolUdpRB.Checked;
            fw.ExternalPort = (ushort)this.externalPort.Value;
            fw.InternalPort = (ushort)this.internalPort.Value;

            this.ParentWizard2.Forwarding = fw;

            // continue
            SetCurrentPage<EditPortForwardingClient>();
        }

        private void externalPort_ValueChanged(object sender, EventArgs e)
        {
            this.internalPort.Value = this.externalPort.Value;
        }
    }
}
